﻿using System;
using System.Linq;
using HashFoo.MigratorFoo;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace HashFoo.MigratorFooTests
{
    [TestClass]
    public class MigrationGeneratorTests
    {
        public string MockAssemblyPath
        {
            get { return Helpers.MockAssemblyPath; }
        }

        [TestMethod]
        public void CanGetSchemaUpdate()
        {
            Helpers.NukeDatabase();

            var generator = new MigrationGenerator
                            {
                                Config = new DbConfigurationReflector(MockAssemblyPath)
                                    .GetAllConfigurations()
                                    .First()
                                    .NhibConfig
                            };

            var schema = generator.GenerateMigration();

            Assert.IsTrue(!string.IsNullOrEmpty(schema.UpScript));
            Console.WriteLine(@"Schema:" + Environment.NewLine + schema.UpScript);
        }

        [TestMethod]
        [Description("Tests that NH Validation attributes are included in schemas (We don't support NH Validation right now because it has a hard time keeping up with NHibernate releases.)")]
        [Ignore]
        public void NhValidationIncludedInSchema()
        {
            Helpers.NukeDatabase();

            var generator = new MigrationGenerator
            {
                Config = new DbConfigurationReflector(MockAssemblyPath)
                    .GetAllConfigurations()
                    .First()
                    .NhibConfig
            };

            var schema = generator.GenerateMigration();

            Assert.IsTrue(!string.IsNullOrEmpty(schema.UpScript));
            Assert.IsTrue(schema.UpScript.Contains("BusinessName NVARCHAR(200) not null"));
            Console.WriteLine(@"Schema:" + Environment.NewLine + schema.UpScript);
        }
    }
}